package com.voute.View.Fragement;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.voute.Base.BaseFragment;
import com.voute.R;
import com.voute.Utils.ViewUtils;
import com.voute.View.Adapter.DiscoveryLocalFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 发现和本地Fragment，其中包含发现和本地两种
 * 下部使用Viewpager，上面使用TabLayout
 */
public class DiscoveryLocalFragment extends BaseFragment {

//    private TabLayout tab_layout;
    private ViewPager view_pager;
    private List<BaseFragment> fragments = new ArrayList<>();
    private List<String> titles = new ArrayList<>();
    private DiscoveryLocalFragmentAdapter mDiscoveryLocalFragmentAdapter;

    private TextView tv_circle_title;
    private View view_circle_bottom;
    private TextView tv_discovery_title;
    private View view_discovery_bottom;

    private RelativeLayout layout_circle;
    private RelativeLayout layout_discovery;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_discovery_local;
    }

    @Override
    public void setupView() {
//        tab_layout = (TabLayout) $(tab_layout);
        view_pager = (ViewPager) $(R.id.view_pager);
        tv_circle_title=$(R.id.tv_circle_title);
        view_circle_bottom=$(R.id.view_circle_bottom);
        tv_discovery_title=$(R.id.tv_discovery_title);
        view_discovery_bottom=$(R.id.view_discovery_bottom);

        layout_circle=$(R.id.layout_circle);
        layout_discovery=$(R.id.layout_discovery);
    }

    @Override
    public void setupData() {
        fragments.clear();
        titles.clear();
        BaseFragment discoveryFragment = ViewUtils.createFragment(DiscoveryFragment.class, false);
        Bundle bundle_movie = new Bundle();
        bundle_movie.putString("feed_type", "circle");
        discoveryFragment.setArguments(bundle_movie);
        BaseFragment localFragment = ViewUtils.createFragment(DiscoveryFragment.class, false);
        Bundle bundle_tv = new Bundle();
        bundle_tv.putString("feed_type", "discovery");
        localFragment.setArguments(bundle_tv);
        fragments.add(discoveryFragment);
        fragments.add(localFragment);
        titles.add("圈子");
        titles.add("发现");
        mDiscoveryLocalFragmentAdapter = new DiscoveryLocalFragmentAdapter(getChildFragmentManager(), titles, fragments);
        view_pager.setAdapter(mDiscoveryLocalFragmentAdapter);
//        tab_layout.setupWithViewPager(view_pager);
//        tab_layout.setTabsFromPagerAdapter(mDiscoveryLocalFragmentAdapter);
        view_pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
            @Override
            public void onPageSelected(int position) {
                if(position==0){
                    tv_circle_title.setTextColor(Color.parseColor("#333333"));
                    tv_discovery_title.setTextColor(Color.parseColor("#666666"));
                    view_circle_bottom.setVisibility(View.VISIBLE);
                    view_discovery_bottom.setVisibility(View.INVISIBLE);
                }
                else if(position==1){
                    tv_circle_title.setTextColor(Color.parseColor("#666666"));
                    tv_discovery_title.setTextColor(Color.parseColor("#333333"));
                    view_discovery_bottom.setVisibility(View.VISIBLE);
                    view_circle_bottom.setVisibility(View.INVISIBLE);
                }
            }
        });
        layout_circle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                view_pager.setCurrentItem(0);
            }
        });
        layout_discovery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                view_pager.setCurrentItem(1);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
    }
}
